import {Body, Controller, Delete, Get, Param, PipeTransform, Post, Query} from '@nestjs/common';
import {TagService} from "./tag.service";
import {TagEntity} from "./entity/tag.entity";
import {TagPipe} from "../../pipe/tag.pipe";
import {TagFileEntity} from "./entity/tagFile.entity";

@Controller('tag')
export class TagController {

    constructor(
        private tagService: TagService
    ) {
    }

    @Get()
    async fetch(@Query() {keyWords}) {
        return this.tagService.fetch(keyWords)
    }

    @Post()
    async save(@Body() data: TagEntity) {
        return this.tagService.save(data)
    }

    @Delete()
    async remove(@Query("ids") ids: string[]) {
        return this.tagService.remove(ids);
    }

    @Get("files")
    async fetchTagFiles(@Query("tagIds") tagIds?: string[]) {
        return this.tagService.fetchTagFiles(tagIds)
    }

    @Post("files")
    async saveTagFile(@Body() data: TagFileEntity) {
        return this.tagService.saveTagFile(data);
    }

    @Get("files/path/:filePath")
    async getByFilePath(@Param("filePath") filePath: string) {
        return this.tagService.getByFilePath(filePath)
    }

}
